package chapter6;
/****************************************************************
 * Author：icynlau
 * Description: 验证有效密码
■ A password must have at least eight characters.

■ A password consists of only letters and digits.

■ A password must contain at least two digits.
 * Date:2021/4/6
 * ***************************************************************
 */
public class pta6_2 {
	
	public static void main(String[] args) {
        java.util.Scanner input = new java.util.Scanner(System.in);
        String s = input.nextLine();

        if (isValidPassword(s)) {
            System.out.println("Valid password");
        }
        else {
            System.out.println("Invalid password");
        }
    }
	
	public static boolean isValidPassword(String pwd) {
		//pwd  password
		boolean flag=true;
		
		if(pwd.length()<8) {
			
//			System.out.print("Valid Password  密码长度少于8位字符");
			flag=false;
			return flag;
		}
		
		int n=0;   //计算数字数量
		
		for(int i=0;i<pwd.length();i++) {
			if(  ! (     Character.isDigit(pwd.charAt(i))   )  &&  !  (   Character.isLetter(pwd.charAt(i))   )) {
				
//				System.out.print("Valid Password  密码必须仅含数字和字母");
				flag=false;
				return flag;
			}
			
			if(  Character.isDigit(pwd.charAt(i))  ) {
				
				n++;
				
			}
		}
		
		if(n<2) {
			
//			System.out.print("Valid Password  密码必须至少包含两个数字");
			flag=false;
			return flag;
		}
		
		
		return flag;
	}
}
